﻿using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

using HMEngine.HMObjects;

namespace HMEngine.HMEffects {
    public delegate void HMEffectParameterHandler(Effect myEffect, HMObject myObject);

    public class HMEffect {
        protected string myAsset;
        protected Effect myEffect;

        public Effect Effect { get { return myEffect; } }
        public event HMEffectParameterHandler SetUserParameters;

        internal HMEffect() { myAsset = "Microsoft.Xna.Framework.Graphics.BasicEffect"; }

        public HMEffect(string asset) { myAsset = asset; }

        internal virtual void LoadContent(GraphicsDevice myDevice, ContentManager myLoader) {
            switch (myAsset) {
                case "Microsoft.Xna.Framework.Graphics.BasicEffect":
                    myEffect = new BasicEffect(myDevice, null);
                    break;
                default:
                    myEffect = myLoader.Load<Effect>(myAsset);
                    break;
            }
        }

        internal virtual void SetParameters(HMObject myObject) {
            if (null != SetUserParameters) SetUserParameters(myEffect, myObject);

            myEffect.CommitChanges();
        }
    }
}